<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>注册会员</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">     
    <meta content="yes" name="apple-mobile-web-app-capable">     
    <meta content="black" name="apple-mobile-web-app-status-bar-style">     
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/login.shell.css?v=2" />
</head>
<body>
    <div class="page-group ms-controller" :controller="register">
        <div class="page page-current">
            <div class="content">
                <div class="login_shell">
                    <div class="login_logo login_logo01"><a href="/H5"><img src="/logo" class="maxWidth" /></a></div>
                    <div class="login_inpt login_inpt01">
                        <input type="text" :duplex="@phone" style="" class="number_tel" placeholder="请填写您的手机号码"/>
                        <!--<span style='font-size: .65rem;color: #fff;width: 27%;text-align: center;float:right; margin-top: 1.2rem; border-radius: 5px; padding: 4px; background-color: #f48a00;' class='getCode' :on-click="@getCode">获取验证码</span>-->
                        <!--<input type="text" name="code" class="number_password" :duplex="code" placeholder="验证码"/>-->
                        <input type="text" name="person" :duplex="person" class="number_tel" placeholder="推荐人手机号/邮箱/用户名"/>
                        <input type="password" name="password" style="position:absolute; top:0; left: 0; visibility: hidden" placeholder="密码"/>
                        <input type="password" autocomplete="off" name="password" :duplex="@password" class="number_password" placeholder="请设置您的登录及支付密码"/>
                        <input type="password" :duplex="@confirm" class="number_password1" placeholder="请确认您的登录及支付密码"/>
                    </div>
                    <div class="login_button">
                        <div class="login_zc">已有账号！<a href="login.html" style="color:#0075c5;">我要登录</a></div>
                        <button id="register" :on-click="@register">立 即 注 册</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/mall.js?v=10' charset='utf-8'></script>
<script>
    var register = avalon.define({
        $id: "register",
        phone: "",
        person: "",
        code:"",
        password: "",
        inviteCode: simpleStorage.get( "inviteCode" )||"",
        confirm: "",
        getCode: function(){
            if( $('.getCode').text() == "获取验证码" ){
                var time = 60;
                $('.getCode').text( time );
                Mall.request( "/api/getSmsCode", {mobile: register.phone} )
                    .always( function( data ){
                        if( data.error_code == 0 ){
                            var timer = setInterval( function(){
                                $('.getCode').text( time );
                                time -- ;
                                if( time <= 0 ){
                                    $('.getCode').text( "获取验证码" );
                                    clearInterval( timer )
                                }
                            },1000 )
                            $.toast( "获取验证码成功", 1000, "success" )
                        }
                        else{
                            $('.getCode').text( "获取验证码" );
                        }
                    } )
            }
        },
        register: function(){
            if( Mall.LOCK ){
                return
            }
            var msg = "";
            if( register.password != register.confirm ){
                msg = "两次密码输入不一致"
            }
            if( msg ){
                $.toast( msg, 2000, "warning" );
                return
            }
            $("#register").text( "注 册 中" );
            var postData = {
                mobile: register.phone,
                email: register.email,
                password: register.password,
                confirm_password: register.confirm,
                code: register.code
            }
            Mall.LOCK = true;
            register.person && ( postData.referer = register.person );
//            simpleStorage.get("inviteCode") && ( postData.referer = simpleStorage.get("inviteCode") );
            Mall.request( "/api/Register", postData )
                .always( function( data ){
                    if( data.error_code == 0 ){
                        $.toast( "恭喜注册成功", 1000, "success", function(){
                            // simpleStorage.set("token", data.data.api_token);
                            // simpleStorage.set("expire_time", data.data.expire_time*1000);
                            // var url = window.location.href;
                            // if( simpleStorage.get("toUrl") ){
                            //     window.location.href = simpleStorage.get("toUrl");
                            // }
                            // else{
                            //     window.location.href="/H5";
                            // }
                            window.location.href="/H5/login"
                        } );
                    }
                    $("#register").text( "立 即 注 册" );
                    Mall.LOCK = false;
                } )
        }
    });
    if(!simpleStorage.get("wap_reg_api_open")){
        document.getElementById('register').style.display="none";
        $.alert('站外注册功能已关闭，请使用微信扫码注册');
        window.location.href="/"

    }
    avalon.scan( document.body )
</script>
</body>
</html>
